package com.my.aslife.controller;

import com.my.aslife.module.common.ErrorCode;
import com.my.aslife.module.common.PageRequestVo;
import com.my.aslife.module.common.ResponseResult;
import com.my.aslife.module.entity.Feedback;
import com.my.aslife.service.FeedBackService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author mayuan
 * @description TODO
 */
@Slf4j
@RestController
@RequestMapping("/api/my/feedback")
public class FeedBackController {

    @Autowired
    private FeedBackService feedBackService;

    @PostMapping("/commit/admin/feedback")
    public ResponseResult commitAdminFeedBack(@RequestBody Feedback feedback){
        return feedBackService.commitAdminFeedBack(feedback);
    }

    @PostMapping("/put")
    public ResponseResult commitFeed(@RequestBody Feedback feedback){
        if (feedback.getUid() == null || feedback.getComment() == null || feedback.getComment().length() <= 5) {
            return ResponseResult.failed(ErrorCode.ERROR_FEEDBACK);
        }
        return feedBackService.commitFeed(feedback);
    }

    @PostMapping("/get/{id}")
    public ResponseResult queryFeedBackInfoByFeedBackId(@PathVariable Long id){

        return feedBackService.queryFeedBackInfoByFeedBackId(id);
    }

    /**
     * @param uid
     * @return
     */
    @PostMapping("/list/{uid}")
    public ResponseResult getFeedBackList(@PathVariable Long uid){
        return feedBackService.getFeedBackList(uid);
    }

    @GetMapping("/get/list")
    public ResponseResult selectFeedBackInfoByPageAndCondition(@RequestParam Integer current, @RequestParam Integer pageSize,
                                                            @RequestParam(value = "orderId", required = false) String orderId) {

        PageRequestVo pageRequestVo = new PageRequestVo(current, pageSize);

        return feedBackService.selectFeedBackInfoByPageAndCondition(pageRequestVo);
    }

}
